package cn.edu.zjut.mina.util;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

/**
 * 解决跨域请求问题
 * @author lingjie
 * @time 2016年8月29日
 *
 */
public class myCORSFilter implements Filter {

	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub

	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		HttpServletResponse response1 = (HttpServletResponse) response; 
		response1.setHeader("Access-Control-Allow-Origin", "*"); 
		response1.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); 
		response1.setHeader("Access-Control-Max-Age", "3600"); 
		response1.setHeader("Access-Control-Allow-Headers", "x-requested-with,Authorization"); 
		response1.setHeader("Access-Control-Allow-Credentials","true"); 
		chain.doFilter(request, response);
	}

	public void destroy() {
		// TODO Auto-generated method stub

	}

}
